from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from data.curtain_control.routers import router as curtain_router
from data.system_info.routers import router as system_router
from data.blob_control.routers import router as blob_router
from data.fan_control.routers import router as fan_router
from data.door_control.routers import router as door_router
from data.oled_control.routers import router as oled_router
from data.async_tcp_server import server

tags_metadata = [
    {
        "name": "窗帘控制",
        "description": "控制窗帘状态的一系列API"
    },
    {
        "name": "系统信息",
        "description": "系统的一系列信息操作API"
    },
    {
        "name": "灯泡控制",
        "description": "灯泡的API"
    },
    {
        "name": "风扇控制",
        "description": "风扇的API"
    },
    {
        "name": "门禁控制",
        "description": "门禁的API"
    },
    {
        "name": "OLED控制",
        "description": "OLED的API"
    }
]

server.setDaemon(True)
server.start()

app = FastAPI(openapi_tags=tags_metadata)
app.include_router(system_router)
app.include_router(curtain_router)
app.include_router(blob_router)
app.include_router(fan_router)
app.include_router(door_router)
app.include_router(oled_router)

templates = Jinja2Templates(directory="./static")
#
# app.mount("/images", StaticFiles(directory="./static/images"), name="image")
app.mount("/css", StaticFiles(directory="./static/css"), name="static")
app.mount("/js", StaticFiles(directory="./static/js"), name="static")
app.mount("/fonts", StaticFiles(directory="./static/fonts"), name="static")
app.mount("/images", StaticFiles(directory="./static/images"), name="static")

@app.get("/")
def home(request: Request):
    return templates.TemplateResponse(
        "index.html",
        {
            "request": request
        }
    )
